class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {


        unordered_map<int, int> mymap;

        int cnt = 0, sum = 0;

        mymap[0] = 1;

        for (int i = 0; i < nums.size(); i++)
        {
            sum += nums[i];

            if (mymap.count(sum - k) > 0)   cnt += mymap[sum - k];

            mymap[sum]++;
        }

        return cnt;

    }
};